home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / FREQ.TST / MAG.AWK < prev    next >
Text File  |  1994-07-09  |  1KB  |  66 lines

  1. # -------
  2. # mag.awk
  3. # -------
  4. BEGIN\
  5. {
  6.     printf("Calculating P = sqrt(X^2 + Y^2)\n");
  7.     printf("Enter X: ");
  8.     getline  x;
  9.     printf("Enter Y: ");
  10.     getline  y;
  11.  
  12.     x = (x < 0) ? -x : x;
  13.     y = (y < 0) ? -y : y;
  14.  
  15.     printf("x = %e, y = %e\n", x, y);
  16.  
  17.     if (x < y)
  18.     {
  19.         t = x; x = y; y = t;
  20.     }
  21.     if (x == 0)
  22.     {
  23.         ans = 0;
  24.     }
  25.     else
  26.     {
  27.     if (1 <= x)
  28.     {
  29.         xp = 2; x = x * 0.25; y = y * 0.25;
  30.     }
  31.     else
  32.     {
  33.        xp = -2; x *= 4; y *= 4;
  34.     }
  35.     t = x - y;
  36.     if (t == x)
  37.     {
  38.         printf("Using Part 0.\n");
  39.         ans = x;
  40.     }
  41.     else if (y < t)
  42.     {
  43.         printf("Using Part 1.\n");
  44.         q = x / y;
  45.         ans = x + y/(q + sqrt(q*q + 1));
  46.     }
  47.     else
  48.     {
  49.         printf("Using Part 2.\n");
  50.         r2 = sqrt(2);        printf("r2 = %.14f\n", r2);
  51.         xh = 2.4142;
  52.         xl = r2 - 1.4142;        printf("xl = %.14f\n", xl);
  53.         q = t / y;
  54.         r = (q + 2) * q;
  55.         s = r / (r2 + sqrt(r + 2)) + xl + q + xh;
  56.  
  57.         ans = x + y / s;
  58.     }
  59.  
  60.     ans *= 2^xp;
  61.     }
  62.  
  63.     printf("answer = %.16e\n", ans);
  64.     printf("x = %e, y = %e, t = %e\n", x, y, t);
  65. }
  66.